package vaccine.appointment.system.vaccine.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 疫苗类型枚举类
 */
@Getter
@AllArgsConstructor
public enum VaccineTypeEnum {
    COMMON(0, "普通疫苗"),
    CHILD(1, "儿童疫苗"),
    ADULT(2, "成人疫苗");

    private final Integer code;
    private final String description;

    /**
     * 根据名称获取枚举对象
     * @param name 名称
     * @return 枚举对象
     */
    public static VaccineTypeEnum forName(String name) {
        for(VaccineTypeEnum vaccineTypeEnum : VaccineTypeEnum.values()) {
            if(vaccineTypeEnum.name().equalsIgnoreCase(name)) {
                return vaccineTypeEnum;
            }
        }
        return null;
    }

    /**
     * 根据code获取描述
     * @param code 类型码
     * @return 描述
     */
    public static String getDescByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for(VaccineTypeEnum type : VaccineTypeEnum.values()) {
            if(type.getCode().equals(code)) {
                return type.getDescription();
            }
        }
        return "";
    }
}
